<template>
  <f-chart :options="chartOption"></f-chart>
</template>
<script setup lang="ts">
import { ChartConfiguration } from 'chart.js';
import { reactive } from 'vue';

const chartOption = reactive<ChartConfiguration>({
  type: 'line',
  data: {
    labels: ['1', '2', '3', '4', '5', '6'],
    datasets: [
      {
        fill: 'start',
        label: '#',
        data: [100, 10, 120, 180, 220, 280],
        tension: 0.3,
        borderColor: '#0DA59A',
        borderWidth: 2,
        pointRadius: 2,
        backgroundColor: (context) => {
          const chart = context.chart;
          const { ctx, chartArea } = chart;
          if (!chartArea) {
            return null;
          }

          const gradient = ctx.createLinearGradient(0, chartArea.bottom, 0, chartArea.top);
          gradient.addColorStop(0, '#FFFFFF'); // 渐变色底部
          gradient.addColorStop(1, '#CDE8E5'); // 渐变色顶部

          return gradient;
        }
      }
    ]
  },
  options: {
    layout: {},
    plugins: {
      legend: { display: false },
      tooltip: {
        mode: 'index',
        intersect: false
      }
    },
    scales: {
      y: {
        grid: { display: false },
        ticks: {
          maxTicksLimit: 8,
          autoSkip: false
        }
      },
      x: {
        offset: true,
        grid: { display: false },
        type: 'category'
      }
    }
  }
});
</script>
